<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打印菱形和三角形</title>
</head>
<body>
    <script>
        var n=prompt("请输入行数:");
        for(i=1;i<=n;i++){
            for(j=1;j<=n-i;j++){
                document.write("&nbsp");
            }
            for(k=1;k<=2*i-1;k++){
                document.write("*");
            }
            document.write("<br>")
        }
        for(l=n-1;l>=1;l--){
            for(m=n-l;m>=1;m--){
                document.write("&nbsp");
            }
            for(o=2*l-1;o>=1;o--){
                document.write("*");
            }
            document.write("<br>")
        }
        for(p=1;p<=4;p++){
            for(r=1;r<=p;r++){
                document.write("*");
            }
            document.write("<br>")
        }
    </script>
</body>
</html>